Skip to content

Conversation

@cfriedt
Copy link
Member

@cfriedt cfriedt commented Nov 10, 2024

  • cmake: flash: update cmake to support rtt target
  • west: runners: jlink: print RTT server port
  • west: runners: openocd: mitigate pylint R0201 warning
  • west: runners: openocd: fix rtt implementation

Fixes #81156

Testing done:

west build -p -S rtt-console -b <board> -t flash samples/hello_world/
...
west rtt -r openocd --cmd-pre-init 'adapter serial <serial>'
...
*** Booting Zephyr OS build v4.0.0-371-g8b7d3d663704 ***
Hello World! <board>
west build -p -S rtt-console -b <board> -t flash samples/hello_world/
...
west rtt -r jlink
...
*** Booting Zephyr OS build v4.0.0-371-g8b7d3d663704 ***
Hello World! <board>

Note

Due to the init strategy for the RTT buffer, either a power-cycle or reflash is required between west rtt invocations
to observe the Hello World message again, since buffer contents and positions are preserved by default (e.g. from
mcuboot). A simple reset via gdb is not sufficient to clear the RTT buffer. Alternatively, manually erase the RTT block
via gdb memory write commands.

@cfriedt cfriedt changed the title scripts: west_commands: core: run netcat with check_call() west: fix broken telnet runner and rtt implementation for openocd Nov 10, 2024
@cfriedt cfriedt force-pushed the fix-rtt-for-openocd-west-twister branch 2 times, most recently from 08b259a to c24f446 Compare November 10, 2024 15:11
@cfriedt cfriedt requested a review from pdgendt November 10, 2024 15:13
@cfriedt cfriedt force-pushed the fix-rtt-for-openocd-west-twister branch 2 times, most recently from 3c6597c to 0f06a1e Compare November 10, 2024 15:26
@cfriedt cfriedt requested a review from dkalowsk November 10, 2024 15:27
@cfriedt cfriedt force-pushed the fix-rtt-for-openocd-west-twister branch from 0f06a1e to 1ced67f Compare November 10, 2024 16:02
@cfriedt
Copy link
Member Author

cfriedt commented Nov 10, 2024

Some questions atm

  1. Does the JLink runner always load the binary again, or does it simply used what was previously flashed to the device? If the latter case, then it's much easier both for west and twister
  2. Does the JLink runner run JLinkRTTClient in the foreground or background? I assumed it was in the foreground based on the existence of run_telnet_client() in jlink.py
  3. Does the JLink runner run the gdb server in the foreground or background? Based on jlink.py, I believe that the gdb server should be run in the background (which would mean changes to openocd.py)

I'll have to double-check on a different machine and modify as necessary for consistence.

Still need to look at simplifying the Twister integration, but it should really be something along the lines of

twister \
  -i \
  -p <board> \
  --device-testing \
  --west-flash \
  --west-runner $RUNNER \
  --device-serial-pty rtt \
  -T samples/hello_world

Kind of awkward, but the --device-serial-pty script part might need .elf awareness for openocd, unless we want to use the base of SRAM and the size of SRAM as the search parameters for rtt setup. Otherwise, it would be kind of nice to specify something like --device-serial-pty rtt and to let twister sort out the app-specific details.

In any case, the openocd setup seems to be much more reliable than the JLink setup, although it's possible that the main problem with the JLink setup was due to #81194.

dkalowsk
dkalowsk previously approved these changes Nov 10, 2024
Copy link
Contributor

@dkalowsk dkalowsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haven't tested these. Overall the changes match to what the commits talk about and seem logical to me. Thanks for the PR!

@cfriedt cfriedt force-pushed the fix-rtt-for-openocd-west-twister branch from 1ced67f to 5081f51 Compare November 13, 2024 19:01
@cfriedt cfriedt changed the title west: fix broken telnet runner and rtt implementation for openocd west: fix broken rtt implementation for openocd Nov 13, 2024
@cfriedt cfriedt force-pushed the fix-rtt-for-openocd-west-twister branch from 5081f51 to 7bbe474 Compare November 15, 2024 22:14
@cfriedt cfriedt force-pushed the fix-rtt-for-openocd-west-twister branch from 7bbe474 to 8b7d3d6 Compare November 18, 2024 18:35
@cfriedt
Copy link
Member Author

cfriedt commented Nov 18, 2024

Just to follow up here

  1. Does the JLink runner always load the binary again, or does it simply used what was previously flashed to the device? If the latter case, then it's much easier both for west and twister

JLink does not load the binary via the rtt runner, and so that functionality was removed for openocd runner as well to be consistent.

  1. Does the JLink runner run JLinkRTTClient in the foreground or background? I assumed it was in the foreground based on the existence of run_telnet_client() in jlink.py

It is run in the foreground.

  1. Does the JLink runner run the gdb server in the foreground or background? Based on jlink.py, I believe that the gdb server should be run in the background (which would mean changes to openocd.py)

It is run in the background (or rather, the TCP port is left open for gdb clients to connect).

The two runners should behave quite similarly now.

@cfriedt cfriedt force-pushed the fix-rtt-for-openocd-west-twister branch from 8b7d3d6 to be3caf7 Compare November 19, 2024 14:25
@cfriedt
Copy link
Member Author

cfriedt commented Nov 19, 2024

  • fixed comments
  • split fix for R0201 into separate commit
  • rebased on latest from main

@cfriedt cfriedt force-pushed the fix-rtt-for-openocd-west-twister branch from be3caf7 to f143d0d Compare November 19, 2024 14:29
@cfriedt
Copy link
Member Author

cfriedt commented Nov 19, 2024

  • reworded git commit messages to be be more uniform

@cfriedt cfriedt force-pushed the fix-rtt-for-openocd-west-twister branch 2 times, most recently from d045f8f to 8bf540e Compare November 19, 2024 14:42
@cfriedt cfriedt changed the title west: fix broken rtt implementation for openocd west: runners: openocd: fix broken rtt implementation Nov 19, 2024
@pdgendt
Copy link
Contributor

pdgendt commented Nov 19, 2024

@topisani PTAL

@fabiobaltieri fabiobaltieri assigned cfriedt and unassigned tejlmand Nov 19, 2024
@fabiobaltieri
Copy link
Member

reassigning, does not really fall under build system, or any other area that I can tell

Add support for the rtt target so that users can run

`west build -p auto -b <board> -t rtt <app>`

similarly to the way that users can now do so with the debug
target, since the rtt target is supposed to be used in a similar
way.

Signed-off-by: Chris Friedt <[email protected]>
Similar to how print_gdbserver_message() prints GDB server info
when "west debug" is run, print RTT server info when "west rtt"
is run.

Signed-off-by: Chris Friedt <[email protected]>
Previously, there was a warning that the to_num() method can
(and probably should) be unbound from OpenOcdBinaryRunner.

Signed-off-by: Chris Friedt <[email protected]>
Previously, rtt start would always fail because the target
(i.e. firmware) had not been started.

```
Info : rtt: Searching for control block 'SEGGER RTT'
Info : rtt: No control block found
```

When the command is 'rtt', run the binary via gdb before calling
'rtt start'. Firmware calls `SEGGER_RTT_Init()` shortly after
init which allows OpenOCD to find the RTT control block.

Similarly, only start the 'rtt server' after calling
'rtt start' to avoid any potential race conditions
internally within OpenOCD.

Signed-off-by: Chris Friedt <[email protected]>
@cfriedt cfriedt force-pushed the fix-rtt-for-openocd-west-twister branch from 8bf540e to a17356a Compare November 20, 2024 18:27
@cfriedt
Copy link
Member Author

cfriedt commented Nov 20, 2024

Looks like unrelated tests are failing - rebased (hopefully the unrelated issues are fixed already)

@cfriedt
Copy link
Member Author

cfriedt commented Nov 21, 2024

@pdgendt - please revisit when you have a moment

@topisani
Copy link
Contributor

Sorry for the wait, LGTM

@fabiobaltieri fabiobaltieri merged commit b85e198 into zephyrproject-rtos:main Nov 21, 2024
35 checks passed
@cfriedt cfriedt deleted the fix-rtt-for-openocd-west-twister branch November 21, 2024 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

west: rtt: console output is non-functional with openocd runner

8 participants